]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Scale and unscale the area for HiDpi displays
authorDebarshi Ray <debarshir@gnome.org>
Mon, 16 Jun 2014 18:28:17 +0000 (20:28 +0200)
committerDebarshi Ray <debarshir@gnome.org>
Tue, 17 Jun 2014 19:22:35 +0000 (21:22 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=731738

js/ui/screenshot.js

index 4c9c750d0552ea5ba218926d837cf97e81f0c097..2f17729b9dc51ec554c95b5f906807f5cf03424b 100644 (file)
@@ -85,8 +85,27 @@ const ScreenshotService = new Lang.Class({
         invocation.return_value(retval);
     },
 
+    _scaleArea: function(x, y, width, height) {
+        let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+        x *= scaleFactor;
+        y *= scaleFactor;
+        width *= scaleFactor;
+        height *= scaleFactor;
+        return [x, y, width, height];
+    },
+
+    _unscaleArea: function(x, y, width, height) {
+        let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+        x /= scaleFactor;
+        y /= scaleFactor;
+        width /= scaleFactor;
+        height /= scaleFactor;
+        return [x, y, width, height];
+    },
+
     ScreenshotAreaAsync : function (params, invocation) {
         let [x, y, width, height, flash, filename, callback] = params;
+        [x, y, width, height] = this._scaleArea(x, y, width, height);
         if (!this._checkArea(x, y, width, height)) {
             invocation.return_error_literal(Gio.IOErrorEnum,
                                             Gio.IOErrorEnum.CANCELLED,
@@ -121,9 +140,9 @@ const ScreenshotService = new Lang.Class({
         selectArea.connect('finished', Lang.bind(this,
             function(selectArea, areaRectangle) {
                 if (areaRectangle) {
-                    let retval = GLib.Variant.new('(iiii)',
-                        [areaRectangle.x, areaRectangle.y,
-                         areaRectangle.width, areaRectangle.height]);
+                    let retRectangle = this._unscaleArea(areaRectangle.x, areaRectangle.y,
+                        areaRectangle.width, areaRectangle.height);
+                    let retval = GLib.Variant.new('(iiii)', retRectangle);
                     invocation.return_value(retval);
                 } else {
                     invocation.return_error_literal(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
@@ -134,6 +153,7 @@ const ScreenshotService = new Lang.Class({
 
     FlashAreaAsync: function(params, invocation) {
         let [x, y, width, height] = params;
+        [x, y, width, height] = this._scaleArea(x, y, width, height);
         if (!this._checkArea(x, y, width, height)) {
             invocation.return_error_literal(Gio.IOErrorEnum,
                                             Gio.IOErrorEnum.CANCELLED,